package com.caigou.service.impl;

import com.caigou.bean.cms.entity.ArticleAdjunct;
import com.caigou.mapper.cms.ArticleAdjunctMapper;
import com.caigou.pojo.ArticleAdjunctData;
import com.caigou.pojo.ArticleDataAdjunctListData;
import com.caigou.service.ArticleAdjunctService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("articleAdjunctService")
public class ArticleAdjunctServiceImpl implements ArticleAdjunctService {

    @Resource
    private ArticleAdjunctMapper articleAdjunctMapper;

    @Override
    public ArticleAdjunct saveArticleAdjunctData(String userId, String articleId, String adjunctName, String adjunctUrl, Integer showIndex) {
        ArticleAdjunct articleAdjunct = new ArticleAdjunct();
        articleAdjunct.setUserId(userId);
        articleAdjunct.setArticleId(articleId);
        articleAdjunct.setAdjunctName(adjunctName);
        articleAdjunct.setAdjunctUrl(adjunctUrl);
        articleAdjunct.setShowIndex(showIndex);
        articleAdjunctMapper.saveArticleAdjunctData(articleAdjunct);
        return articleAdjunct;
    }

    @Override
    public int deleteArticleAdjunct(Integer id) {
        return articleAdjunctMapper.deleteArticleAdjunct(id);
    }

    @Override
    public int updateArticleAdjunct(Integer id, String adjunctName, String adjunctUrl) {
        ArticleAdjunct articleAdjunct = new ArticleAdjunct();
        articleAdjunct.setId(id);
        articleAdjunct.setAdjunctName(adjunctName);
        articleAdjunct.setAdjunctUrl(adjunctUrl);
        return articleAdjunctMapper.updateArticleAdjunct(articleAdjunct);
    }

    @Override
    public List<ArticleDataAdjunctListData> loadArticleAdjunctDataList(String articleId) {
        return articleAdjunctMapper.loadArticleAdjunctDataList(articleId);
    }

    @Override
    public int loadArticleAdjunctMaxVersion(String articleId) {
        return articleAdjunctMapper.loadArticleAdjunctMaxVersion(articleId);
    }

    public int deleteArticleAdjunctByArticleId(String articleId){
        return articleAdjunctMapper.deleteArticleAdjunctByArticleId(articleId);
    }
}
